<?php 
header("Content-type:text/html;charset=utf8");//告诉浏览器编码格式
	  //intval转换成整数
	  $q =  isset($_GET["q"]) ? intval($_GET["q"]) : '';
	 if (empty($q)) {
	 	die("请选择一个网站");
	 }
    require_once("../Const.php");
     var_dump($q);
   try {
   	  $host = host;
      $dbname = "pdo_db";

    	$pdo = new PDO("mysql:host=$host;dbname=$dbname",mysql_username,mysql_password);
    	$pdo -> setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
    //对于数据库中null和空串的处理，可以设置成转换为空串PDO::NULL_TO_STRING
        $pdo -> setAttribute(PDO::ATTR_ORACLE_NULLS,PDO::NULL_NATURAL);

   	  $pdo -> exec("SET NAMES utf8");//编码
      
      $sql = "SELECT * FROM websites WHERE id = $q";
      
      $pdoStmt = $pdo -> prepare($sql);
      $pdoStmt -> execute();
      $pdoStmt -> setFetchMode(PDO::FETCH_ASSOC);
      $result = $pdoStmt -> fetchAll();
   
      var_dump($result);
      
            echo "<table border='1'><tr>
<th>ID</th>
<th>网站名</th>
<th>网站 URL</th>
<th>Alexa 排名</th>
<th>国家</th>
</tr>";

        if (count($result)==1) {
      	$result = $result[0];
      	 foreach ($result as $key => $value) {
		    echo "<td>" . $value. "</td>";
	     }

      }

echo "</table>";

  $pdo = null;
   } catch (Exception $e) {
   	 die($e-> getMessage());
   }
  






 ?>